package com.dongdongshop.controller;

import com.dongdongshop.admin.model.TbSeller;
import com.dongdongshop.admin.vo.SellerVO;
import com.dongdongshop.common.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.nio.file.Watchable;
import java.util.List;

@RestController
@RequestMapping("seller")
public class SellerController {
    @Autowired
    private SellerService sellerService;
    //根据主键查询
    @PostMapping("getSellerByName")
    public Result getSellerByName(@RequestParam("username") String sellerId){
        SellerVO sellerVO = sellerService.getSellerByName(sellerId);
        return Result.OK().setData(sellerVO);
    }
    //注册
    @PostMapping("addSeller")
    public Result addSeller(@RequestBody SellerVO sellerVO){
        List<TbSeller> list = sellerService.getAll(null);
        for (TbSeller tbSeller : list) {
            if (tbSeller.getSellerId().equals(sellerVO.getSellerId())) {
                return Result.Response(ResultEnum.REGISTER_USER_IS_EXIST);
            }
        }
        sellerService.addSeller(sellerVO);
        return Result.OK();
    }

    //商家审核查询
    @PostMapping("getAllSeller")
    public Result<SellerVO> getAllSeller(@RequestParam String name,@RequestParam String nickName){
        List<SellerVO> list = sellerService.getAllSeller(name,nickName);
        return Result.OK().setData(list);
    }

    //修改审核状态
    @PostMapping("updateStauts")
    public Result updateStauts(@RequestBody SellerVO sellerVO){
        sellerService.updateStauts(sellerVO);
        return Result.OK();
    }
}
